package springboot.mybatis.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import springboot.HtmlModel.Html;
import springboot.login.domain.User;
import springboot.mybatis.model.TbUserManagement;
import springboot.mybatis.mapper.TbUserManagementMapper;
import springboot.mybatis.service.ITbUserManagementService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mybatis_plus
 * @since 2017-12-04
 */
@Service
public class TbUserManagementServiceImpl extends ServiceImpl<TbUserManagementMapper, TbUserManagement> implements ITbUserManagementService {

    @Autowired
    private TbUserManagementMapper tbUserManagementMapper;

    /**
     * 用来查看域名是否正常，如果不正常则更换域名生成新的HTML文件
     * @param username 域名查询之后传的参数
     */
    @Override
    public String test(String username) {
        String message;

        try {
            User user = tbUserManagementMapper.findByUsername(username);


            Integer userid = user.getUserid();

            List<User> userList;
            if (userid == 0) {//域名正常

                message = "域名正常";

            } else if (userid == 3) {//查询过于频繁

                message = "查询过于频繁，请稍后再查询";

            } else {//域名错误
                userList = tbUserManagementMapper.findByUserid(0);
                String password = userList.get(0).getPassword();
                Html.MakeHtml(password, "F:\\", "aaa1");
                tbUserManagementMapper.updateUserps(user.getUsername(), user.getPassword(), user.getUserid(), user.getUserps());

                message = user.getUserps() + "以重新生成HTML页面，位于F盘下，名为aaa1";
            }
        }catch (Exception e){
            message = "输入的url不存在";
        }


        return message;

    }
}
